<!-- Content Header (Page header) -->
<section class="content-header">
 <h1>域名列表</h1>
</section>
<!-- Main content -->
<section class="content">
 <!-- /.row -->
 <div class="row">
  <div class="col-xs-12">
   <div class="box">
    <div id="domain-list-container" class="box-body table-responsive no-padding">
    </div>
    <!-- /.box-body -->
   </div>
   <!-- /.box -->
  </div>
 </div>
</section>
<script id="domain-list-tpl" type="text/html">
<table class="table table-hover">
  <%for(var i = 0; i < list.length; i++) {%>
  <% if(i==0){%>
  <tr>
   <th>域名</th>
   <th>管理</th>
  </tr>
  <%}%>
  <tr>
   <td><%:=list[i].name%></td>
   <td><a href="javascript:;" onclick="domain_name='<%:=list[i].name%>';domain_id='<%:=list[i].id%>';load_page('/pages/domain/edit.html');">编辑</a>&nbsp;&nbsp;<a href="javascript:;" data-id="<%:=list[i].id%>" class="domain-delete">删除</a></td>
  </tr>
  <%}%>
 </table>
</script>
<script type="text/javascript">
    $(function(){
        api_invoke("/api/v1/domain/all", {}, function(data){
            if(data.errno == 0){
                var html = template($("#domain-list-tpl").html(), {list: data.info});
                $("#domain-list-container").html(html);
                    $(".domain-delete").click(function(){
                        var id=$(this).attr("data-id");
                        if(confirm("确定删除该域名?删除后该域名所有相关配置都将被删除")){
                            delete_domain(id);
                        }
                    });
            }else{
                alert(data.msg);
            }
        });
    });
    
    function delete_domain(id){
        api_invoke("/api/v1/domain/delete", {domain_id:id}, function(data){
            if(data.errno == 0){
                load_page("/pages/domain/list.html");
                update_menu();
            }else{
                alert(data.msg);
            }
        });
    }
</script>
